package org.meeting.radish.interceptor;

import org.meeting.radish.util.CookieUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Cookie uidCookie = CookieUtil.getCookie(request.getCookies(), "uid");
        if (uidCookie == null || uidCookie.getValue().equals("-1")) {
            response.sendRedirect("/login");
            return false;
        }
        return true;
    }
}
